let server = require('../../utils/server.js');
import ConfigData from '../../utils/globaldata';

function getFactoryIdList() {
    let factoryList =ConfigData.getFactoryList();
    let factoryIds = [];
    for (let i = 0; i < factoryList.length; i++) {
        factoryIds[i] = factoryList[i].id;
    }
    return factoryIds;
}


export default class Present {
    initData(callback) {
        let factoryIds = getFactoryIdList();
        let stationMap = ConfigData.getStationMap();
        wx.showLoading({
            title: '初始化',
        });
        server.getMultiFactoryRuntimeData(factoryIds, res => {
            wx.hideLoading();
            let resultData = res.data.data;
            let newValueList = [];
            for (let i = 0; i < resultData.length; i++) {
                let bean = resultData[i];
                newValueList.push({
                    stationName: stationMap[bean.stationCode].name,
                    dateTime: bean.dateTime,
                    list: bean.valueList
                });
            }
            callback(newValueList);
        })
    }
};

